#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=1e6+5;
int n,k;
namespace sub1{
	int f[22],vis[22];
	string a[555555];
	string biao[11]={"0","1","2","3","4","5","6","7","8","9"};
	int cnt=0;
	void dfs(int x){
		if(x==n+1){
			int ok=1,sum=0;
			for(int i=1;i<n;i++){
				sum+=f[i];
				ok&=(sum>f[i+1]);
			}if(!ok)return;
			string s="";
			for(int i=1;i<=n;i++)s=s+(biao[f[i]]);
			a[++cnt]=s;
			return;
		}
		for(int i=1;i<=n;i++){
			if(!vis[i]){
				vis[i]=1;
				f[x]=i;
				dfs(x+1);
				vis[i]=0;
			}
		}
	}
	inline void solve(){
		dfs(1);
		sort(a+1,a+1+cnt);
		for(int i=1;i<=n;i++)cout<<a[k][i-1]<<' ';
	}
}
signed main(){
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	n=read();k=read();
	if(n<=8)sub1::solve(),exit(0);
	if(k==1){
		printf("3 1 2 ");
		for(int i=4;i<=n;i++)printf("%lld ",i);
		return 0;
	}if(k==2){
		printf("3 1 2 ");
		for(int i=4;i<=n-2;i++)printf("%lld ",i);
		printf("%lld %lld",n,n-1);
		return 0;
	}
	return 0;
}

